package algorithm.leetcode.array;

/**
 * @program: util
 * @description: 删除排序数组中的重复项
 * @author: zhouliangliang
 * @create: 2021-04-12 21:09
 **/
public class DeleteSameNumInSortArray {

    private void delete(int[] array) {
        int i=0;
        int j=1;
        boolean jump = false;
        while (j < array.length) {
            if(array[i] != array[j] && jump == Boolean.FALSE) {
                i++;
                j++;
            }

            if(array[i] == array[j]) {
                j++;
                jump = Boolean.TRUE;
            }

            if(array[i] != array[j] && jump == Boolean.TRUE) {
                array[i+1] = array[j];
                i++;
                j++;
                jump = Boolean.FALSE;
            }
        }

        for(int index=0; index<array.length; index++) {
            System.out.print(array[index]);
        }
    }

    public static void main(String[] args) {
        int []array = new int[]{0,0,1,1,1,2,2,3,3,4};
        new DeleteSameNumInSortArray().delete(array);
    }

}
